﻿/*
getLoadData大集合
getPage获取页（按用户、按创建时间、按更新时间）
getRegion获取页内容
addBook创建笔记本
addArea创建分区！
addPage创建页！
delBook彻底删除笔记本！
delArea彻底删除分区！
delPage彻底删除页
reNameBook重命名笔记本！
reNameArea重命名分区！
reNamePage重命名页
editBookSort更新笔记本排序！
editAreaSort更新分区排序！
editPageSort更新页排序
shareBook分享笔记本！
shareArea分享笔分区
sharePage分享页
unShareBook取消分享笔记本！
unShareArea取消分享分区！
unSharePage取消分享页！
throwPage回收页
renewRegion保存页内容
*/



(function ($) {
    $.Ajax32 = {
        /*----------------------------------------------------*/
        bookAreaPage1: function (options) {
            var defaults = {};
            var options = $.extend({}, defaults, options);
            $.post("/NoteBook/GetNoteBookListAndAreaList", {}, function (data, status) {
                if (status != "success") {
                    alert("获取笔记本列表异常，请刷新页面！");
                    return;
                }
                return data;
            });
        },

        /*----------------------------------------------------便签*/
        bookAreaPage2: function (options) {
            var defaults = {};
            var options = $.extend({}, defaults, options);
            $.post("/NoteBook/GetNoteBookListAndAreaList", {}, function (data, status) {
                if (status != "success") {
                    alert("获取便签列表异常，请刷新页面！");
                    return;
                }
                return data;
            });
        },

        /*----------------------------------------------------页*/
        page: function (options) {
            var defaults = {};
            var options = $.extend({}, defaults, options);
            $.post("/NoteBook/GetNoteBookListAndAreaList", {}, function (data, status) {
                if (status != "success") {
                    alert("获取便签列表异常，请刷新页面！");
                    return;
                }
                return data;
            });
        },

        /*----------------------------------------------------域*/
        region: function (options) {
            var defaults = {};
            var options = $.extend({}, defaults, options);
            $.post("/NoteBook/GetNoteBookListAndAreaList", {}, function (data, status) {
                if (status != "success") {
                    alert("获取便签列表异常，请刷新页面！");
                    return;
                }
                return data;
            });
        },












        /*----------------------------------------------------共享笔记本*/
        shareBook: function (options) {
            var defaults = {
                callback: function () { }
            };
            var options = $.extend({}, defaults, options);
            $.post("/NoteBook/Share", { notebookID: options.params.notebookID }, function (data, status) {
                if (status != "success") {
                    alert("网络异常，请稍后再试！");
                    return;
                }
                if (data.Message == 1) {
                    options.callback(data);
                }
            });
        },

        /*----------------------------------------------------共享分区*/
        shareArea: function (options) {
            alert(options.params.areaID);
            var defaults = {
                callback: function () { }
            };
            var options = $.extend({}, defaults, options);
            $.post("/Area/Share", { areaID: options.params.areaID }, function (data, status) {
                if (status != "success") {
                    alert("网络异常，请稍后再试！");
                    return;
                }
                if (data.Message == 1) {
                    options.callback(data);
                }
            });
        },

        /*----------------------------------------------------共享页*/
        sharePage: function (options) {
            var defaults = {
                callback: function () { }
            };
            var options = $.extend({}, defaults, options);
            $.post("/Page/Share", { pageID: options.params.pageID }, function (data, status) {
                if (status != "success") {
                    alert("网络异常，请稍后再试！");
                    return;
                }
                if (data.Message == 1) {
                    options.callback(data);
                }
            });
        },

        /*----------------------------------------------------取消共享笔记本*/
        unShareBook: function (options) {
            var defaults = {
                callback: function () { }
            };
            var options = $.extend({}, defaults, options);

            $.post("/NoteBook/CancelShare", { notebookID: options.params.id }, function (data, status) {
                if (status != "success") {
                    alert("网络异常，请稍后再试！");
                    return;
                }
                if (data.Message == 1) {
                    options.callback(data);
                }
            });
        },

        /*----------------------------------------------------取消共享分区*/
        unShareArea: function (options) {
            var defaults = {
                callback: function () { }
            };
            var options = $.extend({}, defaults, options);

            $.post("/Area/CancelShare", { areaID: options.params.areaID }, function (data, status) {
                if (status != "success") {
                    alert("网络异常，请稍后再试！");
                    return;
                }
                if (data.Message == 1) {
                    options.callback(data);
                }
            });
        },

        /*----------------------------------------------------取消共享页*/
        unSharePage: function (options) {
            var defaults = {
                callback: function () { }
            };
            var options = $.extend({}, defaults, options);

            $.post("/Page/CancelShare", { pageID: options.params.pageID }, function (data, status) {
                if (status != "success") {
                    alert("网络异常，请稍后再试！");
                    return;
                }
                if (data.Message == 1) {
                    options.callback(data);
                }
            });
        },

        /*----------------------------------------------------彻底删除笔记本*/
        delBook: function (options) {
            var defaults = {
                params: null, //参数集合
                callback: function () { } //回调函数
            };
            var options = $.extend({}, defaults, options);

            $.post("/NoteBook/Delete", { notebookID: options.params.notebookID }, function (data, status) {
                if (status != "success") {
                    alert("网络异常，请稍后再试！");
                    return;
                }
                if (data.Message == 1) {
                    options.callback(data);
                }
            });
        },

        /*----------------------------------------------------彻底删除分区*/
        delArea: function (options) {
            var defaults = {
                params: null, //参数集合
                callback: function () { } //回调函数
            };
            var options = $.extend({}, defaults, options);

            $.post("/Area/Delete", { areaID: options.params.id }, function (data, status) {
                if (status != "success") {
                    alert("网络异常，请稍后再试！");
                    return;
                }
                if (data.Message == 1) {
                    options.callback(data);
                }
            });
        },

        /*----------------------------------------------------彻底删除页*/
        delPage: function (options) {
            var defaults = {
                params: null, //参数集合
                callback: function () { } //回调函数
            };
            var options = $.extend({}, defaults, options);

            $.post("/Page/Delete", { pageID: options.params.pageID }, function (data, status) {

                if (status != "success") {
                    alert("网络异常，请稍后再试！");
                    return;
                }
                alert(33);
                if (data.Message == 1) {
                    options.callback(data);
                }
            });
        },

        /*----------------------------------------------------上传笔记本排序*/
        editBookSort: function (options) {
            var defaults = {
                params: null, //参数集合
                callback: function () { } //回调函数
            };
            var options = $.extend({}, defaults, options);

            $.post("/NoteBook/UpdateNoteBookSort", { notebookSort: options.params.sort }, function (data, status) {
                if (status != "success") {
                    alert("网络异常，请稍后再试！");
                    return;
                }
                if (data.Message == 1) {
                    options.callback(data);
                }
            });
        },

        /*----------------------------------------------------上传某笔记本的分区排序*/
        editAreaSort: function (options) {
            var defaults = {
                params: null, //参数集合
                callback: function () { } //回调函数
            };
            var options = $.extend({}, defaults, options);
            $.post("/NoteBook/UpdateAreaSort", {
                notebookID: options.params.notebookID,
                areaSort: options.params.areaSort
            }, function (data, status) {
                if (status != "success") {
                    alert("网络异常，请稍后再试！");
                    return;
                }
                if (data.Message == 1) {
                    options.callback();
                }
            });
        },

        /*----------------------------------------------------上传某分区的页排序*/
        editPageSort: function (options) {
            var defaults = {
                params: null, //参数集合
                callback: function () { } //回调函数
            };
            var options = $.extend({}, defaults, options);

            $.post("/Area/UpdatePageSortType", {
                areaID: options.params.id,
                pageSort: options.params.sort,
                pageSortType: "Custom"
            }, function (data, status) {
                if (status != "success") {
                    alert("网络异常，请稍后再试！");
                    return;
                }
                if (data.Message == 1) {
                    options.callback(data);
                }
            });
        },

        /*----------------------------------------------------获取笔记本、分区、页数据*/
        getLoadData: function (options) {
            var defaults = {
                params: null, //参数集合
                callback: function () { } //回调函数
            };
            var options = $.extend({}, defaults, options);

            $.post("/NoteBook/GetNoteBookListAndAreaList", {}, function (data, status) {
                if (status != "success") {
                    alert("网络异常，请稍后再试！");
                    return;
                }
                if (data.Message == 1) {
                    options.callback(data);
                }
            });
        },

        /*----------------------------------------------------获取页数据*/
        getPage: function (options) {
            var defaults = {
                params: null, //参数集合
                callback: function () { } //回调函数
            };
            var options = $.extend({}, defaults, options);
            $.post("/Page/GetAll", {
                areaID: options.params.areaID,
                pageIndex: options.params.pageIndex,
                pageSize: options.params.pageSize,
                sortType: options.params.sortType
            }, function (data, status) {
                if (status != "success") {
                    alert("网络异常，请稍后再试！");
                    return;
                }
                if (data.Message == 1) {
                    options.callback(data);
                }
            });
        },

        /*----------------------------------------------------获取域，即获取页内容*/
        getRegion: function (options) {
            var defaults = {
                params: null, //参数集合
                callback: function () { } //回调函数
            };
            var options = $.extend({}, defaults, options);
            //alert(options.params.pageID);
            $.post("/Page/Get", {
                pageID: options.params.pageID
            }, function (data, status) {
                if (status != "success") {
                    alert("网络异常，请稍后再试！");
                    return;
                }
                if (data.Message == 1) {
                    //alert(data.Content.length);
                    options.callback(data);
                }
            });
        },

        /*----------------------------------------------------修改笔记本名称*/
        reNameBook: function (options) {
            var defaults = {
                params: null, //参数集合
                callback: function () { } //回调函数
            };
            var options = $.extend({}, defaults, options);

            $.post("/NoteBook/Update", {
                notebookID: options.params.notebookID,
                notebookName: options.params.notebookName
            }, function (data, status) {
                if (status != "success") {
                    alert("网络异常，请稍后再试！");
                    return;
                }
                if (data.Message == 1) {
                    options.callback();
                }
            });
        },

        /*----------------------------------------------------修改分区名称*/
        reNameArea: function (options) {
            var defaults = {
                params: null, //参数集合
                callback: function () { } //回调函数
            };
            var options = $.extend({}, defaults, options);

            $.post("/Area/Update", {
                areaID: options.params.areaID,
                areaName: options.params.areaName
            }, function (data, status) {
                if (status != "success") {
                    alert("网络异常，请稍后再试！");
                    return;
                }
                if (data.Message == 1) {
                    options.callback();
                }
            });
        },

        /*----------------------------------------------------修改页名称*/
        reNamePage: function (options) {
            var defaults = {
                params: null, //参数集合
                callback: function () { } //回调函数
            };
            var options = $.extend({}, defaults, options);
            alert(options.params.pageID + "," + options.params.pageName);
            $.post("/Page/UpdateName", {
                pageID: options.params.pageID,
                pageName: options.params.pageName
            }, function (data, status) {
                if (status != "success") {
                    alert("网络异常，请稍后再试！");
                    return;
                } alert(33);
                if (data.Message == 1) {
                    options.callback();
                }
            });
        },

        /*----------------------------------------------------创建笔记本*/
        addBook: function (options) {
            var defaults = {
                params: null, //参数集合
                callback: function () { } //回调函数
            };
            var options = $.extend({}, defaults, options);

            $.post("/NoteBook/Create", {
                notebookName: options.params.notebookName,
                AreaID: options.params.AreaID
            }, function (data, status) {
                if (status != "success") {
                    alert("网络异常，请稍后再试！");
                    return;
                }
                if (data.Message == 1) {
                    options.callback(data);
                }
            });
        },

        /*----------------------------------------------------创建分区*/
        addArea: function (options) {
            var defaults = {
                params: null, //参数集合
                callback: function () { } //回调函数
            };
            var options = $.extend({}, defaults, options);
            $.post("/Area/Create", {
                notebookID: options.params.notebookID,
                areaName: options.params.areaName
            }, function (data, status) {
                if (status != "success") {
                    alert("网络异常，请稍后再试！");
                    return;
                }
                if (data.Message == 1) {
                    options.callback(data);
                }
            });
        },

        /*----------------------------------------------------创建页*/
        addPage: function (options) {
            var defaults = {
                params: null, //参数集合
                callback: function () { } //回调函数
            };
            var options = $.extend({}, defaults, options);

            $.post("/Page/Create", {
                areaID: options.params.areaID,
                pageName: options.params.pageName,
                pageContent: options.params.pageContent
            }, function (data, status) {
                if (status != "success") {
                    alert("网络异常，请稍后再试！");
                    return;
                }
                if (data.Message == 1) {
                    options.callback(data);
                }
            });
        },

        /*----------------------------------------------------回收页*/
        throwPage: function (options) {
            var defaults = {
                params: null, //参数集合
                callback: function () { } //回调函数
            };
            var options = $.extend({}, defaults, options);

            $.post("/Page/Throw", {
                pageID: options.params.pageID
            }, function (data, status) {
                if (status != "success") {
                    alert("网络异常，请稍后再试！");
                    return;
                }
                if (data.Message == 1) {
                    options.callback();
                }
            });
        },

        /*----------------------------------------------------更新页内容*/
        renewRegion: function (options) {
            var defaults = {
                params: null, //参数集合
                callback: function () { } //回调函数
            };
            var options = $.extend({}, defaults, options);
            //alert(options.params.pageID);
            //alert(options.params.pageContent);
            //alert(options.params.pageContent.length);
            $.post("/Page/Update", {
                pageID: options.params.pageID,
                pageContent: options.params.pageContent
            }, function (data, status) {
                if (status != "success") {
                    alert("网络异常，请稍后再试！");
                    return;
                }
                if (data.Message == 1) {
                    alert("保存成功");
                    options.callback();
                }
            });
        }

    }

})(jQuery);                    //
